<template>
  <el-form :model="formData" label-width="120px">
    <el-form-item label="姓名">
      <el-input v-model="formData.name" maxlength="30" show-word-limit style="width: 300px"/>
    </el-form-item>
    <el-form-item label="手机号">
      <el-input v-model="formData.phone" maxlength="11" show-word-limit style="width: 300px"/>
    </el-form-item>
    <el-form-item label="身份证号">
      <el-input v-model="formData.id" maxlength="19" show-word-limit style="width: 300px"/>
    </el-form-item>
    <el-form-item label="场所列表">
      <el-select v-model="formData.venueId" class="m-2" placeholder="Select" style="width: 300px">
        <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.name"
            :value="item.id"/>
      </el-select>
    </el-form-item>
    <el-form-item label="门牌号">
      <el-input v-model="formData.address" maxlength="30" show-word-limit style="width: 300px"/>
    </el-form-item>
    <el-form-item style="margin-left: 230px">
      <el-button type="primary" @click="add">添加</el-button>
    </el-form-item>
  </el-form>
</template>
<script setup lang="ts">
import {onMounted, ref, reactive,} from 'vue'
import {venueApi, personApi} from '@/api/index'
import {ElMessage} from "element-plus";

const options = ref([])
const formData = reactive({
  id: '',
  name: '',
  phone: '',
  address: '',
  venueId: 0
})
onMounted(() => {
  callVenueApi()
})
const callVenueApi = () => {
  venueApi.select.call().then((res: any) => {
    options.value = res.list
    formData.venueId = res.list[0].id
  })
}
const add = () => {
  personApi.add.call(formData).then((res: any) => {
    if (res === 1) {
      ElMessage({
        showClose: true,
        message: '上传成功',
        type: 'success'
      })
    } else {
      ElMessage({
        showClose: true,
        message: '上传失败',
        type: 'error'
      })
    }
  })
}
</script>

<style scoped>

</style>
